<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>recur | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>recur</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>recur</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/plugins/recur/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/10-plugins/11-recur.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">npm install moment-recur
</code></pre>

							</div>
<p>&#x5982;&#x679C;&#x9700;&#x8981;&#x5904;&#x7406;&#x91CD;&#x590D;&#x7684;&#x65E5;&#x671F;&#xFF0C;&#x5219;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; Casey Trimm &#x7684;&#x63D2;&#x4EF6; <code>moment-recur</code>&#x3002;</p>
<p>&#x6B64;&#x63D2;&#x4EF6;&#x5C06;&#x4F1A;&#x5141;&#x8BB8;&#x4F60;&#x521B;&#x5EFA;&#x57FA;&#x4E8E;&#x957F;&#x5EA6;&#x7684;&#x95F4;&#x9694;&#xFF08;&#x5929;&#x3001;&#x5468;&#x7B49;&#xFF09;&#x548C;&#x57FA;&#x4E8E;&#x65E5;&#x5386;&#x7684;&#x95F4;&#x9694;&#xFF08;&#x6708;&#x4EFD;&#x7684;&#x65E5;&#x671F;&#x3001;&#x5E74;&#x4EFD;&#x7684;&#x6708;&#x4EFD;&#x7B49;&#xFF09;&#x3002;</p>
<p>&#x5B83;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A; <code>matches</code> &#x51FD;&#x6570;&#x6765;&#x6D4B;&#x8BD5;&#x65E5;&#x671F;&#x662F;&#x5426;&#x6839;&#x636E;&#x89C4;&#x5219;&#x96C6;&#x91CD;&#x73B0;&#xFF0C;&#x8FD8;&#x63D0;&#x4F9B;&#x4E86;&#x751F;&#x6210;&#x5668;&#x51FD;&#x6570;&#x6765;&#x83B7;&#x53D6;&#x7CFB;&#x5217;&#x4E2D;&#x7684;&#x4E0B;&#x4E00;&#x4E2A;&#x548C;&#x4E0A;&#x4E00;&#x4E2A;&#x65E5;&#x671F;&#x3002;</p>
<p>&#x4ED3;&#x5E93;&#x3001;&#x6587;&#x6863;&#x548C;&#x66F4;&#x591A;&#x793A;&#x4F8B;&#x53EF;&#x4EE5;&#x5728; <a href="javascript:window.open('http://nodejs.cn/s/zD3gSF');" target="_blank" rel="nofollow">github.com/c-trimm/moment-recur</a> &#x4E0A;&#x627E;&#x5230;&#x3002;</p>
<pre><code class="language-js">var interval = moment( &quot;01/01/2014&quot; ).recur().every(2).days(); // &#x957F;&#x5EA6;&#x95F4;&#x9694;
interval.matches( &quot;01/03/2014&quot; ); // true
interval.next( 2, &quot;L&quot; ); // [&quot;01/03/2014&quot;, &quot;01/05/2014&quot;]
interval.forget( &quot;days&quot; ); // &#x5220;&#x9664;&#x89C4;&#x5219;
interval.dayOfMonth( 10 ); // &#x65E5;&#x5386;&#x95F4;&#x9694;
interval.matches( &quot;05/10/2014&quot; ); // true
interval.previous( 2, &quot;L&quot; ); // [&quot;12/10/2013&quot;, &quot;11/10/2013&quot;]
</code></pre>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">npm install moment-recur
</code></pre>

							</div>
<p>If you need to work with recurring dates, you can use Casey Trimm&apos;s plugin <code>moment-recur</code>.</p>
<p>This plugin will allow you to create length-based intervals (days, weeks, etc.) and calendar-based intervals (daysOfMonth, monthsOfYear, etc.).</p>
<p>It provides a <code>matches</code> function to test whether a date recurs according to the rules set, as well as generator functions to get the next and previous dates in a series.</p>
<p>The repository, documentation, and many more examples can be found at <a href="javascript:window.open('https://github.com/c-trimm/moment-recur');" target="_blank" rel="nofollow">github.com/c-trimm/moment-recur</a></p>
<pre><code class="language-js">var interval = moment( &quot;01/01/2014&quot; ).recur().every(2).days(); // Length Interval
interval.matches( &quot;01/03/2014&quot; ); // true
interval.next( 2, &quot;L&quot; ); // [&quot;01/03/2014&quot;, &quot;01/05/2014&quot;]
interval.forget( &quot;days&quot; ); // Remove a rule
interval.dayOfMonth( 10 ); // Calendar Interval
interval.matches( &quot;05/10/2014&quot; ); // true
interval.previous( 2, &quot;L&quot; ); // [&quot;12/10/2013&quot;, &quot;11/10/2013&quot;]
</code></pre>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>